﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;


namespace lcmyjobs.Web.findjobs
{
    public partial class JobSearchResult : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Application["webid"] != null)
                {
                    this.Title = string.Format("{1}招聘网   {1}人才网   {1}求职网   {1}猎头网 {0}-搜索招聘信息", Application["webname"].ToString(), Application["webregion"].ToString());
                    BindIsFrist(Convert.ToInt32(Application["webid"]));
                    Bind(Convert.ToInt32(Application["webid"]));

                }

            }

        }

        private void BindIsFrist(int atid)
        {
            int c_isfrist = 0;
            int c_reward = 0;
            int c_vip = 0;
            int c_hunter = 0;
            int c_newjob = 0;
            int c_workerclass = 0;


            DataSet ds = new lcmyjobs.BLL.enterprise_releasejob().GetJobsInfo(true, false, false, false, false, false,
                                                atid, 1, 12,
                                                out c_isfrist, out c_reward, out c_hunter, out c_vip, out c_newjob, out c_workerclass);

            StringBuilder str = new StringBuilder(" <ul class='xsqz_nyul'> ");

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                /*
                string str_tmp = lcmyjobs.BLL.Tools.GetStrSub(row["jobs_name"].ToString() + " " + " " + row["name"].ToString(), 16);
                str.Append("<li><span class='jplf_ls'><a href='JobsInfo-"
                    + row["enterprise_rid"] +".html" + "'>"
                    + str_tmp
                    + "</a></span></li>");
                */
                str.Append("<li><span class='jplf_ls'><a href='JobsInfo-"
                    + row["enterprise_rid"] +".html" + "'>"
                    + lcmyjobs.BLL.Tools.GetStrSub(row["jobs_name"].ToString(), 6)
                    + "</a></span>&nbsp;&nbsp;"
                    + lcmyjobs.BLL.Tools.GetStrSub(row["name"].ToString(), 10)
                    + "</li>");
                
            }

            str.Append("</ul>");

            this.lit_ul_isfrist.Text = str.ToString();
        }




        private void Bind(int atid)
        {
            string workerclass = Request["workerclass"];
            string jobsname = Request["jobsname"];
            string areaname = Request["areaname"];
            string tradename = Request["tradename"];
            string salary = Request["salary"];
            string edu = Request["edu"];
            string exp = Request["exp"];
            string majorname = Request["majorname"];
            string lan = Request["lan"];
            string level = Request["level"];
            string releasetime = Request["releasetime"];
            string key_words = Request["key_words"];

            lcmyjobs.Model.searchjobs sj = new Model.searchjobs();

            sj.workerclass = Convert.ToInt32(workerclass);
            sj.workexp_id = Convert.ToInt32(exp);
            sj.edus_id = Convert.ToInt32(edu);
            sj.languages_id = Convert.ToInt32(lan);
            sj.languages_level = Convert.ToInt32(level);
            sj.salarym = Convert.ToInt32(salary);
            sj.key_words = key_words;//关键字

            //if (!string.IsNullOrEmpty(releasetime))
            //{
            //    sj.releasetime = Convert.ToDateTime(releasetime);
            //}

            sj.releasetime = Convert.ToInt32(releasetime);

            if (!string.IsNullOrEmpty(areaname))
            {
                string[] areas = areaname.Split(',');
                if (areas.Length == 1)
                {
                    sj.area_name1 = areas[0];

                    string[] t_area = areas[0].Split('•');
                    if (t_area.Length > 0)
                    {
                        sj.area_name4 = t_area[0];
                    }
                }
                if (areas.Length == 2)
                {
                    sj.area_name1 = areas[0];
                    sj.area_name2 = areas[1];

                    string[] t_area = areas[0].Split('•');
                    if (t_area.Length > 0)
                    {
                        sj.area_name4 = t_area[0];
                    }

                    string[] t_area1 = areas[1].Split('•');
                    if (t_area.Length > 0)
                    {
                        sj.area_name5 = t_area1[0];
                    }
                }
                if (areas.Length == 3)
                {
                    sj.area_name1 = areas[0];
                    sj.area_name2 = areas[1];
                    sj.area_name3 = areas[2];


                    string[] t_area = areas[0].Split('•');
                    if (t_area.Length > 0)
                    {
                        sj.area_name4 = t_area[0];
                    }

                    string[] t_area1 = areas[1].Split('•');
                    if (t_area.Length > 0)
                    {
                        sj.area_name5 = t_area1[0];
                    }

                    string[] t_area2 = areas[2].Split('•');
                    if (t_area.Length > 0)
                    {
                        sj.area_name6 = t_area2[0];
                    }
                }
            }

            if (!string.IsNullOrEmpty(jobsname))
            {
                string[] jobs = jobsname.Split(',');
                if (jobs.Length == 1)
                {
                    sj.job_name1 = jobs[0];
                }
                if (jobs.Length == 2)
                {
                    sj.job_name1 = jobs[0];
                    sj.job_name2 = jobs[1];
                }
                if (jobs.Length == 3)
                {
                    sj.job_name1 = jobs[0];
                    sj.job_name2 = jobs[1];
                    sj.job_name3 = jobs[2];
                }
            }

            if (!string.IsNullOrEmpty(majorname))
            {
                string[] majors = majorname.Split(',');

                if (majors.Length == 1)
                {
                    sj.major_name1 = majors[0];
                }
                if (majors.Length == 2)
                {
                    sj.major_name1 = majors[0];
                    sj.major_name2 = majors[1];
                }
                if (majors.Length == 3)
                {
                    sj.major_name1 = majors[0];
                    sj.major_name2 = majors[1];
                    sj.major_name3 = majors[2];
                }
            }
            if (!string.IsNullOrEmpty(tradename))
            {
                string[] trades = tradename.Split(',');


                if (trades.Length == 1)
                {
                    sj.tradename1 = trades[0];
                }
                if (trades.Length == 2)
                {
                    sj.tradename1 = trades[0];
                    sj.tradename2 = trades[1];
                }
                if (trades.Length == 3)
                {
                    sj.tradename1 = trades[0];
                    sj.tradename2 = trades[1];
                    sj.tradename3 = trades[2];
                }

            }


            int count = 0;

            DataSet ds = new lcmyjobs.BLL.enterprise_releasejob().GetSearch(sj, atid, this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out count);

            this.AspNetPager1.RecordCount = count;


            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();
        }



        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            Bind(Convert.ToInt32(Application["webid"])); ;
        }
    }
}